define(function (require, exports, module) {
    var $ = require('jquery');
    var _ = require('underscore');

    function Modal (container) {
        var that = this;

        var $doc = $(document);

        this.container = $(container).hide();

        this.container.delegate('.modal-close', 'click', function (ev) {
            ev.preventDefault();

            that.hide();
        });

        this.$mask = $('<div class="modal-mask">').hide();

        this.$mask.insertBefore(this.container);

        this.$mask.height($doc.height());
        this.$mask.width($doc.width());
    }

    Modal.prototype.show = function () {
        this._position();
        this.$mask.show();
        this.container.show();
    };

    Modal.prototype.hide = function () {
        this.$mask.hide();
        this.container.hide();
    };

    Modal.prototype._position = function () {
        var width = this.container.width();
        var height = this.container.height();
        var windowJQ = $(window);
        var windowHeight = windowJQ.height();
        var windowWidth = windowJQ.width();
        var body = $('body');
        var leftValueBase = body.scrollLeft();
        var topValueBase = body.scrollTop();
        var leftValue;
        var topValue;

        leftValue = (windowWidth - width) / 2;
        if (leftValue > 0) {
            leftValue += leftValueBase;
        } else {
            leftValue = leftValueBase;
        }

        // topValue = (windowHeight - height) / 2;
        topValue = 100;
        if (topValue > 0) {
            topValue += topValueBase;
        } else {
            topValue = topValueBase;
        }

        this.container.css('left', leftValue).css('top', topValue);
    };

    exports.Modal = Modal;
});